import { getToken, setToken, setUserInfo, getUserInfo } from "@/utils/auth.js";
let user = {
  state: {
    token: getToken(),
    userInfo: JSON.parse(getUserInfo()) || {},
  },
  mutations: {
    SET_TOKEN(state, token) {
      state.token = token;
    },
    SET_USERINFO(state, userinfo) {
      state.userInfo = userinfo;
    },
  },
  actions: {
    setUserInfo({ commit }, userinfo) {
      commit("SET_USERINFO", userinfo);
      setUserInfo(JSON.stringify(userinfo));
    },
    setToken({ commit }, token) {
      commit("SET_TOKEN", token);
      setToken(token);
    },
  },
  namespaced: true,
};

export default user;
